#include "HNNewsScence.h"
#include "Game/GameLib.h"

FV_SINGLETON_STORAGE(HNNewsScence);

HNNewsScence::HNNewsScence()
	:m_kPublicNoticMission(ScriptData<std::string>("address").Value().c_str(),ScriptData<int>("Port").Value())
{
	init();
	m_kPublicNoticMission.setMissionSink(this);
}
HNNewsScence::~HNNewsScence()
{

}
bool HNNewsScence::init()
{
	if (!Node::init())
	{
		return false;
	};

	_layout = CSLoader::createNode("taskLayer.csb");
	addChild(_layout);

	auto btn = (Button*)_layout->getChildByName("Button_close");
	btn->addTouchEventListener(CC_CALLBACK_2(HNNewsScence::BtnCallBack, this));
	
	return true;
}
void HNNewsScence::EnterScence()
{
	
}
void HNNewsScence::hideAll()
{
	setVisible(false);
}

void HNNewsScence::onGPPublicNoticeResult(std::string kKey,int iError,const char* szDescription)
{
// 	if (WidgetFun::getChildWidget(this, kKey) != NULL)
// 	{
// 		WidgetFun::setText(this, kKey, utility::a_u8(szDescription));
// 	}
}

void HNNewsScence::BtnCallBack(Ref* pSender, Widget::TouchEventType touchtype)
{
	Button* btn = (Button*)pSender;
	if (!btn) return;

	switch (touchtype)
	{
		case Widget::TouchEventType::ENDED:
		{
			if (btn->getName().compare("Button_close") == 0)
			{
				SoundFun::playEffect("effect_close.mp3");
				GameManagerBase::InstanceBase().disconnectServer();
				hideAll();
			}
		}
	}
}